var InputForm = Base.extend({

    _dataListModel: null,
    _form: null,

    constructor: function()
    {
        this._dataListModel = UserDataListModel.getInstance();
        this._form = $('#mainForm');
        this._form.bind('submit', handler(this, '_onFormSubmit'));
    },

    _onFormSubmit: function(event)
    {
        event.preventDefault();
        var userData = this._getUserDataFromForm();
        this._sendUserData(userData);
    },

    _getUserDataFromForm: function()
    {
        var userData = new UserData();
        userData.name = this._form.find('#nameField').val();
        userData.sex = this._form.find('#sexField').val();
        var notify = this._form.find('#notifyField').prop('checked');
        userData.notify = (notify) ? 1 : 0;
        userData.comment = this._form.find('#commentField').val();
        return userData;
    },

    _sendUserData: function(userData)
    {
        $.ajax({
            type: 'POST',
            url: '/lab3/user_info_management.php',
            data: userData,
            success: handler(this, '_onSendUserDataSuccess')
        });
    },

    _onSendUserDataSuccess: function(response)
    {
        this._dataListModel.updateFromJson(response);
    }

});
